-
Notifications
You must be signed in to change notification settings - Fork 342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Repair the cache pollution caused by v.tenat != clientConfig.NamespaceId #221
Conversation
Codecov Report
@@ Coverage Diff @@
## master #221 +/- ##
==========================================
- Coverage 52.00% 51.88% -0.12%
==========================================
Files 25 25
Lines 1721 1721
==========================================
- Hits 895 893 -2
- Misses 748 749 +1
- Partials 78 79 +1
Continue to review full report at Codecov.
|
@@ -428,7 +428,7 @@ func longPulling(taskId int) func() error { | |||
} | |||
for _, v := range initializationList { | |||
v.isInitializing = false | |||
cacheMap.Set(util.GetConfigCacheKey(v.dataId, v.group, clientConfig.NamespaceId), v) | |||
cacheMap.Set(util.GetConfigCacheKey(v.dataId, v.group, v.tenant), v) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A better solution might be to use a separate cacheMap for each ConfigClient
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc1.NamespaceId="namespace1"
client, _ := clients.NewConfigClient(
vo.NacosClientParam{
ClientConfig: cc1,
ServerConfigs: sc,
},
)
// key test-data-1@@test-group@@namespace1
_ = client.ListenConfig(vo.ConfigParam{
DataId: "test-data-1",
Group: "test-group",
OnChange: func(namespace, group, dataId, data string) {
//...
},
})
cc2 := new(constant.ClientConfig)
*cc2 = *cc1
cc2.NamespaceId="2"
client, _ = clients.NewConfigClient(
vo.NacosClientParam{
ClientConfig: cc2,
ServerConfigs: sc,
},
)
// key test-data-2@@test-group@@namespace2
_ = client.ListenConfig(vo.ConfigParam{
DataId: "test-data-2",
Group: "test-group",
OnChange: func(namespace, group, dataId, data string) {
//...
},
})
/*
But cachemap keys may be
[ test-data-1@@test-group@@namespace1,
test-data-2@@test-group@@namespace2,
test-data-2@@test-group@@namespace1, // this is wrong
]
*/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
当使用多个namespceId建立客户端监听配置变化时,在此处clientConfig已经不与v对应,cacheMap.Set会造成的缓存异常。